package com.myweb.util;

import java.util.ArrayList;
import java.util.List;

import com.myweb.model.Menu;

public class MenuTree {

	public List<Menu> menuCommon;

	public List<Menu> list = new ArrayList<Menu>();

	public List<Menu> menuList(List<Menu> menus) {
		menuCommon = menus;
		for (Menu menu : menuCommon) {
			if (Integer.parseInt(menu.getMenuLevel()) == 1) {
				menu.setChildList(menuChild(menu.getMenuId()));
				list.add(menu);
			}
		}
		return list;
	}

	public List<Menu> menuChild(int id) {
		List<Menu> childList = new ArrayList<Menu>();
		for (Menu menu : menuCommon) {
			if (menu.getParentId() == id) {
				menu.setChildList(menuChild(menu.getMenuId()));
				childList.add(menu);
			}
		}
		return childList;
	}
}
